Skip to content

Conversation

@lmtr0
Copy link

@lmtr0 lmtr0 commented Apr 1, 2025

Hello there, good day.

General Information

(Background) I needed a more flexible client with a support for auto capture, and I noticed that a lot of the work I was doing in my services was a bunch of boilerplate. With that in mind, I wanted to make it available to everybody so that you don't need to re-implement what I did.

This client includes an auto-capture actor that uses channels and tokio (no deadlocks) to make sure the only thing you need to worry about is the events and not the api client implementation.

There is an initial query api client that I implemented because I need it for my application.

I've features enabled so that you only enable the code you need.

The downside. I removed the code you just merged for blocking clients as I was developing the actor in parallel and it's too late to reverse it now.

This is a follow up on #24

If you want me to change anything let me know, I'll work on it as soon as I can.

Inner workings

I've included the architecture documents I used to develop some of the clients, and what I envision it to be. I've more of the api planned to the future, but, I only have so much time and I need to get the other products out. SO, I might re work some of this in the future

lmtr0 and others added 30 commits February 7, 2025 22:53
Extension Like client api
Implementation of the Capture endpoint with a custom Event Builder
This change adds a new `capture` method to the `PostHogClient` struct. The
`capture` method allows users to send event data to the PostHog `/capture/`
endpoint. The method takes a `serde_json::Value` containing the event data and
returns a `CaptureResponse` struct, which includes the status of the capture
operation.

The new `capture` method includes detailed documentation, including argument
and return value descriptions, as well as an example usage.

Additionally, the `CaptureEndpoints` trait and associated `CaptureResponse`
struct have been moved to the `PostHogClient` implementation directly.
Better separation between sdk and api
This change introduces a new `PostHogAPIClient` struct that provides
a convenient interface for making API requests to the PostHog
platform. The client automatically handles rate limiting and retries,
ensuring that API requests are processed reliably.

The key features of this implementation include:

- Automatic rate limit handling with exponential backoff
- Retry mechanism with a configurable maximum number of retries
- Support for both JSON-based and no-content API responses
- Configurable base URL for the API endpoint
- Abstraction of the underlying HTTP client (using `reqwest`)

This client will be used throughout the PostHog SDK to interact with
the PostHog API, providing a robust and user-friendly experience for
SDK users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant